package com.qibao.toolkit.exception.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author wangcheng
 * @version $Id: ApplicationContextUtils.java, v0.1 2018/9/26 16:33 wangcheng Exp $$
 */
@Component
public class ApplicationContextUtils implements ApplicationContextAware {

    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext context) throws BeansException {
        ApplicationContextUtils.context = context;
    }

    public static <T extends Object> Map<String, T> getBeans(Class<T> clz) {
        return context.getBeansOfType(clz);
    }

    public static <T extends Object> T getBean(Class<T> clz) {
        return context.getBean(clz);
    }

}
